package org.cfg;

import com.sojoys.artifact.build.data.base.BaseCfg;
import java.util.List;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import java.util.ArrayList;
/**
 * 任务
 */
public class TaskCfg extends BaseCfg<TaskCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "task";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.TaskCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 12;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","任务类型","接取任务条件ID","接取任务条件参数","任务完成条件ID","任务完成条件参数","完成进度","奖励资源","是否开启","重置类型","有效时间","初始进度继承任务ID",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","type","acceptCondId","acceptParams","finishCondId","finishParams","progress","reward","open","resetType","effectiveTime","extendsTaskId",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","type","acceptCondId","acceptParams","finishCondId","finishParams","progress","reward","open","resetType","effectiveTime","extendsTaskId",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,3575610,1503802117,1863169198,-1970735536,-1611368455,-1001078227,-934326481,3417674,2023809321,-929905388,792685433,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","int","Map","int","Map","int","Map","boolean","int","int","int",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,Integer.class,Map.class,Integer.class,Map.class,Integer.class,Map.class,Boolean.class,Integer.class,Integer.class,Integer.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 任务类型
	 */
	private int type;
	
	/**
	 * 接取任务条件ID
	 */
	private int acceptCondId;
	
	/**
	 * 接取任务条件参数
	 */
	private Map acceptParams;
	
	/**
	 * 任务完成条件ID
	 */
	private int finishCondId;
	
	/**
	 * 任务完成条件参数
	 */
	private Map finishParams;
	
	/**
	 * 完成进度
	 */
	private int progress;
	
	/**
	 * 奖励资源
	 */
	private Map reward;
	
	/**
	 * 是否开启
	 */
	private boolean open;
	
	/**
	 * 重置类型
	 */
	private int resetType;
	
	/**
	 * 有效时间
	 */
	private int effectiveTime;
	
	/**
	 * 初始进度继承任务ID
	 */
	private int extendsTaskId;
	
	
	
	public static TaskCfg builder() {
		TaskCfg taskCfg = new TaskCfg();
		return taskCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 任务类型
	 */
	public int getType() {
		return type;
	}
	
	/**
	 * 接取任务条件ID
	 */
	public int getAcceptCondId() {
		return acceptCondId;
	}
	
	/**
	 * 接取任务条件参数
	 */
	public Map getAcceptParams() {
		return acceptParams;
	}
	
	/**
	 * 任务完成条件ID
	 */
	public int getFinishCondId() {
		return finishCondId;
	}
	
	/**
	 * 任务完成条件参数
	 */
	public Map getFinishParams() {
		return finishParams;
	}
	
	/**
	 * 完成进度
	 */
	public int getProgress() {
		return progress;
	}
	
	/**
	 * 奖励资源
	 */
	public Map getReward() {
		return reward;
	}
	
	/**
	 * 是否开启
	 */
	public boolean getOpen() {
		return open;
	}
	
	/**
	 * 重置类型
	 */
	public int getResetType() {
		return resetType;
	}
	
	/**
	 * 有效时间
	 */
	public int getEffectiveTime() {
		return effectiveTime;
	}
	
	/**
	 * 初始进度继承任务ID
	 */
	public int getExtendsTaskId() {
		return extendsTaskId;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.type;
        values[2] = this.acceptCondId;
        values[3] = this.acceptParams;
        values[4] = this.finishCondId;
        values[5] = this.finishParams;
        values[6] = this.progress;
        values[7] = this.reward;
        values[8] = this.open;
        values[9] = this.resetType;
        values[10] = this.effectiveTime;
        values[11] = this.extendsTaskId;
        return values;
	}
	
	protected TaskCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.type = (int)vals[1];
		this.acceptCondId = (int)vals[2];
		this.acceptParams = (Map)vals[3];
		this.finishCondId = (int)vals[4];
		this.finishParams = (Map)vals[5];
		this.progress = (int)vals[6];
		this.reward = (Map)vals[7];
		this.open = (boolean)vals[8];
		this.resetType = (int)vals[9];
		this.effectiveTime = (int)vals[10];
		this.extendsTaskId = (int)vals[11];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.type);
        map.put(keys[2], this.acceptCondId);
        map.put(keys[3], this.acceptParams);
        map.put(keys[4], this.finishCondId);
        map.put(keys[5], this.finishParams);
        map.put(keys[6], this.progress);
        map.put(keys[7], this.reward);
        map.put(keys[8], this.open);
        map.put(keys[9], this.resetType);
        map.put(keys[10], this.effectiveTime);
        map.put(keys[11], this.extendsTaskId);
        return map;
    }
    
    protected TaskCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.type = (int)map.get(keys[1]);
   		this.acceptCondId = (int)map.get(keys[2]);
   		this.acceptParams = (Map)map.get(keys[3]);
   		this.finishCondId = (int)map.get(keys[4]);
   		this.finishParams = (Map)map.get(keys[5]);
   		this.progress = (int)map.get(keys[6]);
   		this.reward = (Map)map.get(keys[7]);
   		this.open = (boolean)map.get(keys[8]);
   		this.resetType = (int)map.get(keys[9]);
   		this.effectiveTime = (int)map.get(keys[10]);
   		this.extendsTaskId = (int)map.get(keys[11]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.type);
        obj.put(keys[2], this.acceptCondId);
        obj.put(keys[3], this.acceptParams);
        obj.put(keys[4], this.finishCondId);
        obj.put(keys[5], this.finishParams);
        obj.put(keys[6], this.progress);
        obj.put(keys[7], this.reward);
        obj.put(keys[8], this.open);
        obj.put(keys[9], this.resetType);
        obj.put(keys[10], this.effectiveTime);
        obj.put(keys[11], this.extendsTaskId);
        return obj;
    }
    
    protected TaskCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.type = obj.getIntValue(keys[1]);
	    this.acceptCondId = obj.getIntValue(keys[2]);
		this.acceptParams = obj.getObject(keys[3],Map.class);
	    this.finishCondId = obj.getIntValue(keys[4]);
		this.finishParams = obj.getObject(keys[5],Map.class);
	    this.progress = obj.getIntValue(keys[6]);
		this.reward = obj.getObject(keys[7],Map.class);
	    this.open = obj.getBooleanValue(keys[8]);
	    this.resetType = obj.getIntValue(keys[9]);
	    this.effectiveTime = obj.getIntValue(keys[10]);
	    this.extendsTaskId = obj.getIntValue(keys[11]);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.type);
	    byteBuf.writeInt(this.acceptCondId);
	    byteBuf.writeObject(this.acceptParams);
	    byteBuf.writeInt(this.finishCondId);
	    byteBuf.writeObject(this.finishParams);
	    byteBuf.writeInt(this.progress);
	    byteBuf.writeObject(this.reward);
	    byteBuf.writeBoolean(this.open);
	    byteBuf.writeInt(this.resetType);
	    byteBuf.writeInt(this.effectiveTime);
	    byteBuf.writeInt(this.extendsTaskId);
    }
	
	protected TaskCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.type = byteBuf.readInt(null);
	    this.acceptCondId = byteBuf.readInt(null);
	    this.acceptParams = (Map)byteBuf.readObject();
	    this.finishCondId = byteBuf.readInt(null);
	    this.finishParams = (Map)byteBuf.readObject();
	    this.progress = byteBuf.readInt(null);
	    this.reward = (Map)byteBuf.readObject();
	    this.open = byteBuf.readBoolean(null);
	    this.resetType = byteBuf.readInt(null);
	    this.effectiveTime = byteBuf.readInt(null);
	    this.extendsTaskId = byteBuf.readInt(null);
	    return this;
	}
	
	public TaskCfg deepCopy(){
		TaskCfg taskCfg = null;
		try {
			taskCfg = (TaskCfg) super.clone();
		    taskCfg.acceptParams = ToolCopy.copyObject(this.acceptParams);
		    taskCfg.finishParams = ToolCopy.copyObject(this.finishParams);
		    taskCfg.reward = ToolCopy.copyObject(this.reward);
			return taskCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return taskCfg;
	}
//自定义内容起始位置
//自定义内容结束位置
}
